#include "PLDirectoryMethods.h"

using std::string;

/**
  *	Returns the base path of the file, whose full path is passed as an argument.
  * For c:\baseDir\file1.txt this would be c:\baseDir
  *
  * @param filePath const reference to the full path of the file
  * @return base path of the file
  */
string PL::GetFileBasePath( const string &filePath )
{
	string::size_type index = filePath.find_last_of( "/\\" );

	if (index == string::npos)
		return filePath;

	return filePath.substr( 0, index );
}

/**
  *	Returns the file name that is part of the passed path.
  * For c:\baseDir\file1.txt this would be file1.txt
  * @return file name that is part of the passed path
  */
string PL::GetFileNameFromPath( const string &filePath )
{
	string::size_type index = filePath.find_last_of( "/\\" );

	if (index == filePath.npos)
		return filePath;
	else
		return filePath.substr( index + 1 );
}

/**
  *	Removes the file extension from the path that is passed as an argument.
  * For c:\baseDir\file1.txt this would be c:\baseDir\file1
  *
  * @param filePath const reference to the full path of the file
  * @return path of the file without file extension
  */
string PL::RemoveFileExtension( const string &filePath )
{
	string::size_type index = filePath.rfind( "." );

	if (index == string::npos)
		return filePath;

	return filePath.substr( 0, index );
}